package com.ganmiao.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ganmiao.resp.PageResult;

import java.util.ArrayList;
import java.util.Objects;

/**
 * @Author 刘少波
 * @Date 2022/9/3
 * @Desc 集合分页工具类
 */
public class PageListUtil {

    /**
     * 分页转换
     *
     * @param iPage
     * @param <T>
     * @return
     */
    public static <T> PageResult<T> getPageResult(IPage iPage) {
        PageResult pageResult = new PageResult();
        pageResult.setList(Objects.nonNull(iPage.getRecords()) ? iPage.getRecords() : new ArrayList<>());
        pageResult.setTotalCount(iPage.getTotal());
        pageResult.setTotalPageNum(iPage.getPages());
        pageResult.setNowPage(iPage.getCurrent());
        pageResult.setPageSize(iPage.getSize());
        return pageResult;
    }

}
